<template>
	<view class="" style="background-color: #f1f5f8;">
		<view class="top">
			<view>
				<input type="text" value="" placeholder="搜索关键字" v-model="key"/>
				<text class="iconfont icon-sousuo" @click="getstoreslist"></text>
			</view>
			<view>
				<picker style="line-height: 90rpx; margin-left: 30rpx;" @change="bindTimeChange" :range="array">
				    {{name=='筛选' ? '筛选' : name}}
				</picker>
				<text class="iconfont icon-shaixuan-"></text>
			</view>
		</view>

		<view class="body"  v-for="(item,index) in storeslist">
			<image :src="IMGBASEURL+item.logo" mode=""></image>
			<view class="right" >
				<text>{{item.name}}</text>
				<text>{{item.services}}</text>
				<view @click="detailsId(item.id)">
					查看详情
				</view>
			</view>
		</view>
		   <text class="warning" v-if="nomore">没有更多内容。。。</text>
	</view>
</template>

<script>
	import request from '../../utils/request.js'
	import { storeslist } from '../../api/stores.js'
	import {IMGBASEURL} from '../../utils/config.js'

	
	export default{
		data(){
			return{
				array:[
					'蔬菜水果',
					'早餐早点',
					'服装鞋帽'
				],
				storeslist:[],
				IMGBASEURL:IMGBASEURL,
				page:1,
				psize:8,
				IMGBASEURL: IMGBASEURL,
				key:'',
				name:'筛选',
				nomore:false
			}
		},
		onLoad() {
			this.getstoreslist()
		},
		  onPullDownRefresh() {
		    this.page = 1
		    this.storeslist = []
		    uni.showNavigationBarLoading()//导航栏加载效果loading
		    this.getstoreslist()
		  },
		
		  /**
		   * 页面上拉触底事件的处理函数
		   */
		  onReachBottom() {
		      this.page++
		      this.getstoreslist()
		  },
		methods:{
			bindTimeChange(value){
				this.name = this.array[value.detail.value]
				this.page = 1
				this.getstoreslist(this.name)
			},
			async getstoreslist(value){
				uni.showToast({
					title:'加载中'
				})
				let data = await storeslist({
					page:this.page,
					psize:this.psize,
					key:this.key,
					services:value
				})
				if(data.data.list == 0){
					this.nomore = true
				}
				uni.hideLoading()
				uni.stopPullDownRefresh()
				uni.hideNavigationBarLoading()
				
				let newData = this.storeslist.concat(data.data.list)
				this.storeslist = newData
				

				console.log(this.storeslist)
			},
			detailsId(id){
				if(id){
					uni.navigateTo({
						url:'../Storesdetails/index?id='+id
					})
				}
			}
		}
	}
</script>

<style>
	@import '../../static/style/stores.less';
	.warning{
	  /* background-color: red; */
	  height: 70rpx;
	  line-height: 70rpx;
	  text-align: center;
	}
</style>